package com.fang.guilimall.admin.api.customize.config;

import com.fang.gulimall.admin.common.core.dto.ResponseDTO;
import com.fang.gulimall.admin.common.exception.ApiException;
import com.fang.gulimall.admin.common.exception.error.ErrorCode;
import com.fang.gulimall.admin.common.utils.jackson.JacksonUtil;
import com.fang.gulimall.admin.common.utils.servlet.ServletHolderUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.web.filter.CorsFilter;

/**
 * @ClassName SecurityConfig
 * @Description TODO
 * @Author fangge
 * @Date 2024/6/13 23:23
 */
//@Configuration
//@EnableWebSecurity
//@RequiredArgsConstructor
public class SecurityConfig {
//    /**
//     * token认证过滤器
//     */
//    private final JwtAuthenticationFilter jwtTokenFilter;
//
//
//    /**
//     * 跨域过滤器
//     */
//    private final CorsFilter corsFilter;
//
//
//    /**
//     * 登录异常处理类
//     * 用户未登陆的话  在这个Bean中处理
//     */
//    @Bean
//    public AuthenticationEntryPoint customAuthenticationEntryPoint() {
//        return (request, response, exception) -> {
//            ResponseDTO<Void> responseDTO = ResponseDTO.fail(
//                    new ApiException(ErrorCode.Client.COMMON_NO_AUTHORIZATION, request.getRequestURI())
//            );
//            ServletHolderUtil.renderString(response, JacksonUtil.to(responseDTO));
//        };
//    }
//
//
//
//    @Bean
//    public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
//        httpSecurity.authorizeHttpRequests((authz) -> authz.requestMatchers("/common/**").permitAll()
//                .anyRequest().authenticated()
//        );
//
//        httpSecurity.addFilterBefore(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class);
//        // 添加CORS filter
//        httpSecurity.addFilterBefore(corsFilter, JwtAuthenticationFilter.class);
//
//
//        return httpSecurity.build();
//    }


}

